package com.m1.tzolkin.model.buildables;

import java.util.Collection;
import java.util.HashSet;

import com.m1.tzolkin.model.board.ITechBoard;
import com.m1.tzolkin.model.exceptions.CannotBuildException;
import com.m1.tzolkin.model.exceptions.NoAvailableSkullException;
import com.m1.tzolkin.model.exceptions.NotEnoughCornException;
import com.m1.tzolkin.model.exceptions.NotEnoughResourceException;

public class Farm extends Buildable implements IFarm {
	
	// ATTRIBUTS
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4456874682544951800L;
	private final FarmTypes type;
	
	// CONSTRUCTEUR
	
	public Farm(FarmTypes type) {
		super(type.getCost());
		this.type = type;
	}
	
	// REQUETES

	@Override
	public FarmTypes getFarmType() {
		return type;
	}

	public static Collection<IFarm> createAll(int i) {
		Collection<IFarm> farms = new HashSet<IFarm>();
		switch (i) {
		case 0:
			farms.add(new Farm(FarmTypes.ONE_FED));
			farms.add(new Farm(FarmTypes.ONE_FED));
			farms.add(new Farm(FarmTypes.ONE_FED));
			farms.add(new Farm(FarmTypes.ALL_HALF));
			farms.add(new Farm(FarmTypes.ALL_HALF));
			break;
		case 1:
			farms.add(new Farm(FarmTypes.THREE_FED));
			farms.add(new Farm(FarmTypes.THREE_FED));
			farms.add(new Farm(FarmTypes.THREE_FED));
			break;
		default:
			throw new IllegalArgumentException();
		}
		return farms;
	}

	@Override
	public String getName() {
		return type.name();
	}
	
	// COMMANDES

	@Override
	public void buy(ITechBoard b) throws NotEnoughCornException, NotEnoughResourceException, NoAvailableSkullException, CannotBuildException {
		b.build(this);
	}

}
